'''
Created on Dec 5, 2010

@author: mkiyer
'''
import os

JOB_SUCCESS = 0
JOB_ERROR = 1

def parse_bool(s):
    if s is None:
        return False
    return True if s.lower() in set(["t", "true", "yes", "y"]) else False

def file_exists_and_is_newer(outfile, mtime):    
    if os.path.exists(outfile):
        return os.path.getmtime(outfile) >= mtime
    return False

def file_exists_and_size_gt(outfile, filesize):    
    if os.path.exists(outfile):
        return os.path.getsize(outfile) >= filesize
    return False

def file_newer(outfile, infile):
    return file_exists_and_is_newer(outfile, os.path.getmtime(infile))

def file_newer_and_larger(outfile, infile):
    a = file_exists_and_is_newer(outfile, os.path.getmtime(infile))
    b = file_exists_and_size_gt(outfile, os.path.getsize(infile))
    return a and b

def up_to_date(outfile, infile):
    if not os.path.exists(infile):
        return False
    if not os.path.exists(outfile):
        return False
    if os.path.getsize(outfile) == 0:
        return False    
    return os.path.getmtime(outfile) >= os.path.getmtime(infile)


def job_done(infile):
    jobd=open(infile+'.done','w')
    jobd.close()
    
def up_to_date_job(infile):
    return os.path.exists(infile+'.done')

